package com.bl.student.manager.controller.comment;

import com.bl.student.manager.controller.BaseController;
import com.bl.student.common.ApiResponseBody;
import com.bl.student.service.biz.comment.CommentService;
import com.bl.student.service.vo.DelBody;
import com.bl.student.service.vo.DelListBody;
import com.bl.student.service.vo.comment.CommentAddVo;
import com.bl.student.service.vo.comment.CommentListVo;
import com.bl.student.service.vo.user.UserListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * Created by liangweikang on 18/2/2.
 */
@RestController
@Log4j2
@RequestMapping(value = {"/student/manager/comment"})
@Api(value = "评论api", description = "评论api")
public class CommentController extends BaseController{

    @Autowired
    CommentService commentService;


    @ApiOperation(value = "删除批量", notes = "删除批量评论信息 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del_list"})
    public ApiResponseBody delList(
            @Valid @RequestBody DelListBody body, BindingResult result,
            HttpServletRequest request) {

        commentService.delList(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除评论信息", notes = "删除评论信息 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del"})
    public ApiResponseBody del(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {

        commentService.del(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "评论列表", notes = "评论列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "creatorId", value = "发出评论者id", required = false, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "receiverId", value = "接受评论者id", required = false, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "type", value = "发出评论者type", required = false, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "taskId", value = "任务id", required = false, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "page", value = "页数", required = true, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = true, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_list_multi"})
    public ApiResponseBody<UserListVo> getListMulti(
            @RequestParam(value = "creatorId", required = false, defaultValue = "") String creatorId,
            @RequestParam(value = "receiverId", required = false, defaultValue = "") String receiverId,
            @RequestParam(value = "type", required = false, defaultValue = "") String type,
            @RequestParam(value = "taskId", required = false, defaultValue = "") String taskId,
            @RequestParam(value = "page", required = true, defaultValue = "1") int page,
            @RequestParam(value = "size", required = true, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        CommentListVo commentListVo = commentService.getCommentListMulti(creatorId, receiverId, type, taskId, pageable);

        return ApiResponseBody.createSuccessBody(commentListVo);
    }
}
